package krow.dev.gunpobus.control.http;

import krow.dev.gunpobus.Constants.Parameter;
import krow.dev.gunpobus.Constants.Url;
import krow.dev.gunpobus.GlobalStore;
import krow.dev.gunpobus.control.parser.ScheduleParser;
import krow.dev.gunpobus.control.parser.NodeParser;
import krow.dev.gunpobus.control.parser.RouteParser;
import krow.dev.gunpobus.control.parser.StationParser;
import android.util.Log;

import com.android.volley.Request;

public class RequestManager {

	public static Request<?> requestRoute(HtmlResponseListener<RouteParser> responseListener){
		
		StringBuilder stringBuilder = new StringBuilder(Url.ROUTE);

		HtmlRequest<RouteParser> xmlRequest = new HtmlRequest<RouteParser>(
				stringBuilder.toString(), 
				new RouteParser(), 
				responseListener,
				responseListener);
		
		GlobalStore.getInstance().getRequestQueue().add(xmlRequest);
		
		return xmlRequest;
	}
	
	public static Request<?> requestStation(HtmlResponseListener<StationParser> responseListener){
		
		StringBuilder stringBuilder = new StringBuilder(Url.STATION);

		HtmlRequest<StationParser> xmlRequest = new HtmlRequest<StationParser>(
				stringBuilder.toString(), 
				new StationParser(), 
				responseListener,
				responseListener);
		
		GlobalStore.getInstance().getRequestQueue().add(xmlRequest);
		
		return xmlRequest;
	}
	
	public static Request<?> requestNode(String routeId, HtmlResponseListener<NodeParser> responseListener){
		
		StringBuilder stringBuilder = new StringBuilder(Url.NODE);
		stringBuilder.append("?");
		stringBuilder.append(Parameter.ROUTE_ID).append("=").append(routeId);
		
		HtmlRequest<NodeParser> xmlRequest = new HtmlRequest<NodeParser>(
				stringBuilder.toString(), 
				new NodeParser(), 
				responseListener,
				responseListener);
		
		GlobalStore.getInstance().getRequestQueue().add(xmlRequest);
		
		return xmlRequest;
	}
	
	public static Request<?> requestArrivalState(String stationId, HtmlResponseListener<ScheduleParser> responseListener){
		
		StringBuilder stringBuilder = new StringBuilder(Url.ARRIVAL_STATE);
		stringBuilder.append("?");
		stringBuilder.append(Parameter.STATION_ID).append("=").append(stationId);
		
		Log.e("test", "stete url: " + stringBuilder.toString());
		
		HtmlRequest<ScheduleParser> xmlRequest = new HtmlRequest<ScheduleParser>(
				stringBuilder.toString(), 
				new ScheduleParser(), 
				responseListener,
				responseListener);
		
		GlobalStore.getInstance().getRequestQueue().add(xmlRequest);
		
		return xmlRequest;
	}
}
